﻿package com.tvein.sanguo.swc.crowd
{
	//flash
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.MouseEvent;
	//A3D
	//custom
	import com.tvein.sanguo.swc.common.SwcEvent;
	import com.tvein.sanguo.swc.common.MP3Click;
//
	public class Human extends MovieClip
	{
		public static const NAME:String = "Human";
		
		private var gameConfig:Array;
		private var roleCMD:Object;
		
		public function Human(ID:String, Name:String, Face:int, CMD:Object, sysConfig:Array)
		{
			txtName.text = Name;
			txtName.selectable = false;
			txtName.mouseEnabled = false;
			
			roleCMD = CMD;
			gameConfig = sysConfig;
			
			btnHuman.visible = false;
			
			var faceloader:Loader = new Loader();
			
			faceloader.load(new URLRequest(gameConfig["srcServer"] + "/SanGuo/role/face/" + Face + ".png"));
			faceloader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onFaceLoad);
			
			btnHuman.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function _onFaceLoad(evt:Event):void
		{
			evt.target.removeEventListener(Event.COMPLETE, _onFaceLoad);
			
			evt.target.content.x = 8;
			evt.target.content.y = 8;
			
			this.addChild(evt.target.content);
			
			if (roleCMD.toString() != "")
			{
				btnHuman.visible = true;
			}
		}
		
		private function onClick(evt:MouseEvent):void
		{
			var soundEffect:MP3Click = new MP3Click();
			soundEffect.playback(gameConfig["effectVol"] *.01);
			
			switch(evt.target.name)
			{
				case "btnHuman":
					dispatchEvent(new SwcEvent("CrowdShell", roleCMD, true));
					break;
			}
		}
	}
}